<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->


<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.Type" content="topic">
<meta name="DC.Title" content="步骤2：开启归档模式">
<meta name="product" content="">
<meta name="DC.Relation" scheme="URI" content="zh-cn_topic_0000001792402592.html">
<meta name="prodname" content="">
<meta name="version" content="">
<meta name="brand" content="30-OceanProtect 备份一体机 1.5.0-1.6.0 帮助中心">
<meta name="DC.Publisher" content="20240320">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="ZH-CN_TOPIC_0000001839201717">
<meta name="DC.Language" content="zh-cn">
<link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
<title>步骤2：开启归档模式</title>
</head>
<body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px"><a name="ZH-CN_TOPIC_0000001839201717"></a><a name="ZH-CN_TOPIC_0000001839201717"></a>

<h1 class="topictitle1">步骤2：开启归档模式</h1>
<div><p>在执行数据库备份前必须开启归档模式，否则将会导致备份失败。</p>
<div class="section"><h4 class="sectiontitle">操作步骤</h4><p><strong>方式一：通过修改配置文件参数开启归档模式</strong></p>
<ol><li><span>使用PuTTY，登录PostgreSQL数据库主机。</span></li><li id="ZH-CN_TOPIC_0000001839201717__li72311543204718"><span>在数据库安装Linux操作系统用户的所在目录下创建存放归档日志（WAL日志）的路径，且运行数据库的操作系统用户有读写权限。后续操作以/mnt/server/archivedir/路径为例。</span></li><li><span>修改postgresql.conf文件中的wal_level 、archive_mode和archive_command参数。</span><p><ul><li>将wal_level设置为archive（PostgreSQL 9.6以上版本为replica）及以上。</li><li>将archive_mode设置为on。</li><li>将archive_command设置为 'cp %p /mnt/server/archivedir/%f'，并确保归档日志的路径是单个路径。<div class="note"><img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span><div class="notebody"><p>修改postgresql.conf文件时，请修改文件中已存在的字段值，禁止在文件中自行新增同样的字段，否则将会影响恢复任务。</p>
</div></div>
</li></ul>
<p>例如：</p>
<p>wal_level = replica</p>
<p>archive_mode = on</p>
<p>archive_command = 'cp %p /mnt/server/archivedir/%f'</p>
</p></li></ol>
<p><strong>方式二：通过执行数据库命令开启归档模式</strong></p>
<ol><li><span>使用PuTTY，登录PostgreSQL数据库主机。</span></li><li><span>在数据库安装Linux操作系统用户的所在目录下创建存放归档日志（WAL日志）的路径，且运行数据库的操作系统用户有读写权限。后续操作以/mnt/server/archivedir/路径为例。</span></li><li><span>依次执行以下命令，开启数据库归档模式。</span><p><pre class="screen">alter system set wal_level= 'replica';
ALTER SYSTEM
alter system set archive_mode= 'on';
ALTER SYSTEM
alter system set archive_command ='cp %p /mnt/server/archivedir/%f'</pre>
</p></li><li><span>集群场景下请执行<strong>stemctl restart patroni.service</strong>命令，重启patroni服务。</span><p><p>单机场景下请依次执行<strong>/usr/local/pgsql/bin/pg_ctl -D</strong>和<strong>/usr/local/pgsql/data -l logfile  restart</strong>命令，重启数据库。</p>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>父主题：</strong> <a href="zh-cn_topic_0000001792402592.html">备份PostgreSQL</a></div>
</div>
</div>

<div class="hrcopyright"><hr size="2"></div><div class="hwcopyright">版权所有 &copy; 华为技术有限公司</div></body>
</html>